package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-05 17:17
 **/
public class LeetCode198 {

    public int rob(int[] nums) {
        int n = nums.length;
        if (n == 1) {
            return nums[0];
        }

        int a = nums[0];
        int b = Math.max(a, nums[1]);

        for (int i = 2; i < n; ++i) {
            int c = b;
            b = Math.max(a + nums[i], b);
            a = c;
        }

        return b;
    }

}
